//
//  HSCLabel.m
//  CharacterLocationSeekerDemo
//
//  Created by 红沙尘 on 2018/12/12.
//  Copyright © 2018年 FasaMo. All rights reserved.
//

#import "HSCLabel.h"
#import "CharacterLocationSeeker.h"

@interface HSCLabel () {
    UIView *flagView;
}

@property (strong, nonatomic) CharacterLocationSeeker *locationSeeker;

@end

@implementation HSCLabel

- (void)rectAtIndex:(NSInteger)index {
    
    if (!flagView) {
        flagView = [[UIView alloc] init];
        flagView.frame = CGRectZero;
        flagView.layer.borderColor = [UIColor redColor].CGColor;
        flagView.layer.borderWidth = 1.f;
        flagView.clipsToBounds = YES;
        [self addSubview:flagView];
    }
    
    if (!self.locationSeeker) {
        self.locationSeeker = [CharacterLocationSeeker new];
        [self.locationSeeker configWithLabel:self];
    }
    
    if (index >= self.text.length) {
        index = 0;
    }
    
    CGRect frame = [self.locationSeeker characterRectAtIndex:index];
    
    [UIView animateWithDuration:0.15 animations:^{
        self->flagView.frame = frame;
    }];
    
    
}

@end
